package com.intermancer.trader.account;

public class SimpleTradingAccount implements TradingAccount {

	private static final double DEFAULT_COMMISSION = 5.0;
	private static final double DEFAULT_VALUATION = 1.0;

	private double balance;
	private int position = 0;
	private double tradeCommission = DEFAULT_COMMISSION;
	private double lastValue;
	private double valuation = DEFAULT_VALUATION;

	@Override
	public void adjustPosition(int positionShift, double currentValue) {
		balance += (currentValue - lastValue) * position * valuation;
		balance -= tradeCommission;
		lastValue = currentValue;
		position += positionShift;
	}

	@Override
	public double getBalance() {
		return balance;
	}

	@Override
	public void setBalance(double balance) {
		this.balance = balance;
	}

	public double getTradeCommission() {
		return tradeCommission;
	}

	public void setTradeCommission(double tradeCommission) {
		this.tradeCommission = tradeCommission;
	}

	public double getValuation() {
		return valuation;
	}

	public void setValuation(double valuation) {
		if( valuation != 0.0) {
			this.valuation = valuation;
		}
	}

	@Override
	public double getLastValue() {
		return lastValue;
	}
	
	@Override
	public int getPosition() {
		return position;
	}

}
